<?php

namespace App\Admin\Controllers;

use App\Models\BroughtMembrane;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Encore\Admin\Layout\Content;
use Illuminate\Support\Facades\DB;

class BroughtMembraneController extends Controller
{
    use HasResourceActions;

    //首页
    public function index(Content $content)
    {
        return Admin::content(function (Content $content) {
            $content->header('免费领膜管理');
            $content->body($this->grid());
        });
    }

    protected function grid()
    {
        return Admin::grid(BroughtMembrane::class, function (Grid $grid) {
            $grid->column('id', 'ID')->sortable();
            $grid->provider()->name('服务商');
            $grid->column('phone', '手机号');
            $grid->user()->name('申请用户');
            $grid->column('create_at', '申请时间');

            $grid->disableCreateButton();

            $grid->disableRowSelector();

            $grid->disableActions();

            $grid->actions(function ($actions) {
                $actions->disableDelete();
                $actions->disableView();
            });

            $grid->filter(function($filter){
                // 去掉默认的id过滤器
                $filter->disableIdFilter();

                // 在这里添加字段过滤器
                $filter->column(1/3, function ($filter) {
                    $filter->like('phone', '手机号');
                });
            });

            $grid->tools(function ($tools) {
                // 禁用批量删除按钮
                $tools->batch(function ($batch) {
                    $batch->disableDelete();
                });
            });

            $grid->model()->orderBy('id', 'desc');

            //禁用导出按钮
            $grid->disableExport();
        });
    }
}
